<?php

namespace App\Http\Controllers\Backend;


use App\Models\SiteVersion;
use App\Models\SiteCate;
use Illuminate\Support\Facades\Config;

class SiteVersionController extends BaseController
{
    // 广告
    public function initialize()
    {
        parent::initialize();

        $this->model = 'SiteVersion';
    }

    // 父级
    // 添加，修改，删除，列表，停用 操作


    // 返回列表数据
    public function lists()
    {
        $where = $this->listWhere();
        $page  = $this->page;
        $rows  = $this->rows;
        $model = $this->checkModel($this->model);
        if($model === false){
            return $this->error($this->error);
        }

        // 模型 和 查询
        if($where){
            $result = $model->listPage($where, $page, $rows, "id DESC");
        } else{
            $result = $model->isCache(true)->listPage($where, $page, $rows, "id DESC");
        }

        return $this->success($result);
    }

    // 列表查询
    protected function listWhere()
    {
        $where    = [];
        $platform = $this->getData('platform', null, 'trim');
        $code     = $this->getData('code', null, 'trim');
        $name     = $this->getData('name', null, 'trim');
        if($platform){
            $where[] = ['platform', '=', $platform];
        }
        if($code){
            $where[] = ['code', '=', $code];
        }
        if($name){
            $where[] = ['name', '=', $name];
        }

        return $where;
    }

    // 添加
    protected function _before_add()
    {
        $data = [
            'platform' => $this->getData("platform", null, 'trim'),
            'code'     => $this->getData("code", null, 'trim'),
            'name'     => $this->getData("name", null, 'trim'),
            'url'      => $this->getData("url", null, 'trim'),
            'remark'   => $this->getData("remark", null, 'trim'),
            //'ctime'    => $this->getData("ctime", null, 'trim'),
            //'mtime'    => $this->getData("mtime", null, 'trim'),
        ];


        return $data;
    }

    // 修改
    protected function _before_edit()
    {
        $data = [
            'platform' => $this->getData("platform", null, 'trim'),
            'code'     => $this->getData("code", null, 'trim'),
            'name'     => $this->getData("name", null, 'trim'),
            'url'      => $this->getData("url", null, 'trim'),
            'remark'   => $this->getData("remark", null, 'trim'),
            //'ctime'    => $this->getData("ctime", null, 'trim'),
            //'mtime'    => $this->getData("mtime", null, 'trim'),
        ];


        return $data;
    }

}


